#ifndef __SPDF_EXT_H__
#define __SPDF_EXT_H__

#include "spdf_opt.h"
#include "rtctime.h"
#include "mytype.h"

#ifdef __cplusplus
extern "C"
{
#endif

#define SPDF_FORM_ALAIN_NONE 0
#define SPDF_FORM_ALAIN_MID_X 1
#define SPDF_FORM_ALAIN_MID_Y 2
#define SPDF_FORM_ALAIN_MID 3

	typedef struct
	{
		ii16 site;
		uu08 r, g, b;
	} form_backcolor_type;

	typedef struct
	{
		ii16 x0, y0;
		SPDF_Page page;

		struct
		{
			ii16 num;
			ii16 *size_list;
			ii16 fixd_size;
		} col;

		struct
		{
			ii16 num;
			ii16 size;
		} row;

		struct
		{
			ii16 y_offset, x_offset, font_size, half_wide;
			ii16 x, y;
			ii16 col, row;
			uu8 alain;										   
			uu8 hex_force;									   
			ii16 xzoom;										   
			ii32 (*str_wide)(const char *str, ii16 font_size); 
		} txt;

		struct
		{
			ii16 ext_wide;						   
			ii16 inn_wide;						   
			uu8 ext_r, ext_g, ext_b;			   
			uu8 inn_r, inn_g, inn_b;			   
			uu8 ext_dash_len1;					   
			uu8 ext_dash_len0;					   
			uu8 inn_dash_len1;					   
			uu8 inn_dash_len0;					   
			const form_backcolor_type *row_bcolor; 
			const form_backcolor_type *col_bcolor; 
			uu16 row_bcolor_num;				   
			uu16 col_bcolor_num;				   
		} frame;
	} spdf_form_type;

	typedef struct
	{
		uu8 r, g, b;
	} spdf_color_type;

	void spdf_form_page_mount(spdf_form_type *form, SPDF_Page page);

	void spdf_form_row_set(spdf_form_type *form, ii16 num, ii16 size);

	void spdf_form_col_set(spdf_form_type *form, ii16 num, ii16 *size, ii16 fixed_size);

	void spdf_form_org(spdf_form_type *form, ii16 x, ii16 y);

	void spdf_form_frame_ext_set(spdf_form_type *form, ii16 wide, uu8 r, uu8 g, uu8 b);
	void spdf_form_frame_inn_set(spdf_form_type *form, ii16 wide, uu8 r, uu8 g, uu8 b);

	void spdf_form_draw(spdf_form_type *form);

	void spdf_form_line_sp(spdf_form_type *form,
						   ii16 row, ii16 col,
						   ii16 x0, ii16 y0,
						   ii16 x1, ii16 y1);

	void spdf_form_text_start(spdf_form_type *form);

	void spdf_form_text_end(spdf_form_type *form);

	void spdf_form_text_site(spdf_form_type *form, ii16 row, ii16 col);

	void spdf_form_text_offset(spdf_form_type *form, ii16 x, ii16 y);

	void spdf_form_text_font(spdf_form_type *form, const char *font_name, ii16 size, ii16 half_wide);
	void spdf_form_text_xzoom(spdf_form_type *form, ii16 xzoom);

	void spdf_form_text_alain(spdf_form_type *form, uu8 alain);

	void spdf_form_grid_merge(spdf_form_type *form,
							  ii16 row, ii16 col, ii16 row_num, ii16 col_num,
							  const spdf_color_type *backcolor, const char *text, uu08 line_mode);

	void spdf_form_text(spdf_form_type *form, ii16 row, ii16 col, const char *text);
	void spdf_form_text_ext(
		spdf_form_type *form, ii16 row, ii16 col, const char *text,
		const spdf_color_type *backcolor, const spdf_color_type *forecolor);

	void spdf_form_text_sp(spdf_form_type *form,
						   ii16 row, ii16 col,
						   ii16 x_offset, ii16 y_offset,
						   const char *text);

	void spdf_form_text_next_row(spdf_form_type *form);

	void spdf_form_text_next_col(spdf_form_type *form);

	void spdf_form_text_auto(spdf_form_type *form, const char *text);
	void spdf_form_text_auto_ext(
		spdf_form_type *form, const char *text,
		const spdf_color_type *backcolor, const spdf_color_type *forecolor);

	typedef struct
	{
		uu8 wide;	 
		uu8 r, g, b; 
	} spdf_chart_base_line_type;

	typedef struct
	{
		spdf_chart_base_line_type attr; 
		ii32 site;						
		ii8 len1;						
		ii8 len0;						
		struct
		{
			ii32 dx;		 
			ii32 dy;		 
			const char *str; 
		} text;
	} spdf_chart_hl_type;

	typedef struct
	{
		ii32 site; 
		uu8 wide;  
		ii8 lmode; 
		ii8 len1;  
		ii8 len0;  
		struct
		{
			ii32 dx;		 
			ii32 dy;		 
			const char *str; 
		} xtext;

		struct
		{
			ii32 dx;		 
			ii32 dy;		 
			const char *str; 
		} ytext;
	} spdf_chart_vl_type;

	typedef struct
	{
		ii16 x_pos;
		ii16 val;
	} spdf_chart_point_type;

	typedef struct
	{
		spdf_chart_base_line_type attr; 
		uu16 point_pos_offset;			
		uu16 point_amount;				
		const void *point_val_list;		
		ii32 point_val_coef;			
		ii32 point_val_offset;			
		ii32 axis_y_offset;				
		ii32 axis_x_split_nums;			
		uu8 point_mode;					
										
		uu8 v_l_amount;					
		const spdf_chart_vl_type *v_l;	
	} spdf_chart_line_type;

	typedef struct
	{
		uu8 r, g, b;	  
		uu8 ipn;		  
		uu8 val_attr;	  
		const char *unit; 
		ii32 val_start;	  
		ii32 val_inc;	  
	} spdf_chart_ytxt_type;

	typedef struct
	{
		ii32 x0, y0;		
		ii32 width, height; 
		ii32 xzoom, yzoom;	
		SPDF_Page page;		

		struct
		{
			spdf_chart_base_line_type l_axis;	
			spdf_chart_base_line_type l_grid_m; 
			spdf_chart_base_line_type l_grid_s; 
			ii16 grid_x_m_wide;					
			ii16 grid_y_m_wide;					
			ii8 grid_x_s_num;					
			ii8 grid_y_s_num;					
			ii16 arrows_offset;					
			ii16 arrows_size;					
			uu8 mode;							
			ii16 scale_s_size;					
			ii16 scale_m_size;					
			
			uu8 hl_amount;				  
			const spdf_chart_hl_type *hl; 
		} frame;

		struct
		{
			uu8 x_enable, y_enable; 
			uu8 aux_enable;
			
			uu8 x_mode;			   
			uu8 x_r, x_g, x_b;	   
			uu8 x_val_ipn;		   
			ii16 x_val_inc;		   
			ii32 x_val_start;	   
			micro_time_type x_rtc; 
			ii16 xtxt_dx, xtxt_dy; 

			const spdf_chart_ytxt_type *ytxt; 
			uu8 y_txt_num;					  
			ii16 ytxt_dx, ytxt_dy;			  

			ii16 font_size;									   
			ii16 half_wide;									   
			const char *font_name;							   
			ii16 xzoom;										   
			ii32 (*str_wide)(const char *str, ii16 font_size); 
		} txt;

		uu8 dir;							   
		uu8 line_num;						   
		const spdf_chart_line_type *line_list; 

	} spdf_chart_type;

	void spdf_chart_mount(spdf_chart_type *chart, SPDF_Page page);

	void spdf_chart_show(spdf_chart_type *chart);

	void spdf_chart_default(spdf_chart_type *chart);

	void spdf_chart_axis(spdf_chart_type *chart, uu8 wide, uu8 r, uu8 g, uu8 b);
	void spdf_chart_grid_m(spdf_chart_type *chart, uu8 wide, uu8 r, uu8 g, uu8 b);
	void spdf_chart_grid_s(spdf_chart_type *chart, uu8 wide, uu8 r, uu8 g, uu8 b);

	void spdf_chart_ytxt_color(spdf_chart_ytxt_type *ytxt, uu8 r, uu8 g, uu8 b);
	void spdf_chart_xtxt_color(spdf_chart_type *chart, uu8 r, uu8 g, uu8 b);

	void spdf_chart_txt_show(spdf_chart_type *chart);

	void spdf_chart_line_attr(spdf_chart_line_type *line, uu8 wide, uu8 r, uu8 g, uu8 b);
	void spdf_chart_line_add(spdf_chart_type *chart, const spdf_chart_line_type *line);

	void spdf_chart_ext_move_to(spdf_chart_type *chart, ii32 ax, ii32 ay);
	void spdf_chart_ext_line_to(spdf_chart_type *chart, ii32 ax, ii32 ay);
	void spdf_chart_ext_show_text(
		spdf_chart_type *chart,
		ii32 ax, ii32 ay, ii32 dx, ii32 dy,
		const char *text);
	ii16 pdf_chart_txt_wide(spdf_chart_type *chart, const char *txt);

#ifdef __cplusplus
}
#endif

#endif 
